//
//  ServerSettingWindowController.m
//  HiQ
//
//  Created by arvintan on 12-8-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ServerSettingWindowController.h"

@interface ServerSettingWindowController ()

@end

@implementation ServerSettingWindowController

@synthesize _textServerIp;
@synthesize _textServerPort;
@synthesize _buttonOK;
@synthesize _buttonCancel;

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

- (void)windowDidLoad
{
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}

-(void) awakeFromNib
{
    [_textServerIp becomeFirstResponder];
}

-(void) serverSetting:(NSWindowController *)sender
{
    //用sheet的方式显示窗体，并返回选择结果
    NSWindow *window = [self window];
    [NSApp beginSheet:window
       modalForWindow:[sender window]
        modalDelegate:nil
       didEndSelector:nil
          contextInfo:nil];
    [NSApp runModalForWindow:window];
    
    [NSApp endSheet:window];
    [window orderOut:self];
}


-(IBAction)onClickedOk:(id)sender
{
    [[NSUserDefaults standardUserDefaults] setValue:[_textServerIp stringValue] forKey:@"SERVER_IP"];
    [[NSUserDefaults standardUserDefaults] setValue:[_textServerPort stringValue] forKey:@"SERVER_PORT"];
    [NSApp stopModal]; 
}

-(IBAction)onClickedCancel:(id)sender
{
    [NSApp stopModal];  
}

@end
